<template>
  <div v-loading="loading" class="app-container">
    <div class="head-container">
      <searchForm ref="searchForm" :parent="currentObject" />
    </div>
    <div style="padding-top:5px">
      <el-button type="primary" size="mini" style="float:right;margin-bottom:5px;" icon="el-icon-upload" round @click="doSubmitBPMS">提交审核</el-button>
      <cancel ref="cancel" :parent="currentObject" />
      <dataGrid ref="dataGrid" :parent="currentObject" />
    </div>
    <activeForm ref="activeForm" :parent="currentObject" />
    <urgentForm ref="urgentForm" :parent="currentObject" />
  </div>
</template>

<script>
import activeForm from '@/views/active-item/bpms/bpms-active'
import searchForm from '@/views/active-item/search-form'
import urgentForm from '@/views/new-item/bpms/urgent'
import dataGrid from '@/views/active-item/data-grid'
import initData from '@/utils/initData'
import { Message } from 'element-ui'
import { submitBPMS } from '@/api/active-item'
import common from '@/api/active-global'
import cancel from '@/views/active-item/file/cancel'

export default {
  components: { activeForm, urgentForm, searchForm, dataGrid, cancel },
  mixins: [initData],
  data() {
    return {
      currentObject: this,
      ids: [],
      loading: false,
      itemStatuses: [
        { value: 4, name: '数据校验成功' },
        { value: 5, name: 'Item File审核中' },
        { value: 11, name: 'MDA/BPMS审核中' },
        { value: 10, name: 'BPMS审核中' },
        { value: 100, name: '已发送至Item File出号' }
      ],
      changeType: common.itemType,
      buyerId: ''
    }
  },
  created() {
    this.$nextTick(() => {
      this.init()
    })
  },
  methods: {
    beforeInit() {
      this.url = common.basePath + '/querySubmitBPMSItemTypeMofityList'
      this.params.pageNum = this.page
      this.params.pageSize = this.size
      return true
    },
    // 详情触发
    toItemInfo(item) {
      const activeForm = this.$refs.activeForm
      activeForm.title = '商品转类型-bpms审核页面'
      activeForm.itemInfo = JSON.parse(item.itemInfo)
      activeForm.itemInfo.vendorItemInfo = JSON.parse(item.vendorItemInfo)
      activeForm.itemStatus = item.itemStatus
      activeForm.buyerId = item.buyerId
      activeForm.id = item.id
      activeForm.dialog = true
    },
    // 批量提交审核前置
    doSubmitBPMS() {
      if (this.ids.length < 1) {
        Message({
          message: '请选择需要提交审核的item。',
          type: 'error',
          duration: 3 * 1000
        })
      } else {
        const urgentForm = this.$refs.urgentForm
        urgentForm.itemSize = this.ids.length
        urgentForm.changeType = this.changeType
        urgentForm.bpmsParam.auditBuyerId = this.buyerId
        urgentForm.ids = this.ids
        urgentForm.dialog = true
      }
    },
    // 提交审核操作
    submitBPMS(bpmsParam) {
      this.loading = true
      submitBPMS({ changeType: this.changeType, bpmsParamDTO: bpmsParam, ids: this.ids }).then(res => {
        this.toQuery()
        Message({
          message: '数据提交成功。',
          type: 'success',
          duration: 3 * 1000
        })
        this.loading = false
      }, (error) => {
        console.log(error)
        this.loading = false
      })
    },
    // 查询
    toQuery() {
      this.page = 0
      this.currentPage = 1
      this.init()
      this.$refs.dataGrid.doClearSelection()
    }
  }
}
</script>
